(function () {
    var exports = this;

    var $ = null;

    var TishiLayer = cc.Layer.extend({
        onEnter: function () {
            cc.Layer.prototype.onEnter.call(this);
        },
        onExit: function () {
            cc.Layer.prototype.onExit.call(this);
        },
        ctor: function (type, title, content, onOk, onCancel, canCancel, isHCenter, isVCenter, okRes, cancelRes, titleRes) {
            this._super();

            var that = this;

            content = content || '';

            var scene = ccs.load(res.TishiLayer_json);
            this.addChild(scene.node);
            $ = create$(this.getChildByName("Scene"));
            shipei($);

            if (isHCenter)
                $('root.panel.lb_content').setTextHorizontalAlignment(cc.TEXT_ALIGNMENT_CENTER);
            if (isVCenter)
                $('root.panel.lb_content').setTextVerticalAlignment(cc.TEXT_ALIGNMENT_CENTER);
            $('root.panel.lb_content').setString(content);

            if (type.indexOf('alert') == 0) {
                //$('root.panel.alert').setVisible(true);
                var btnOk = $('root.panel.btn_ok');
                var btnCancel = $('root.panel.btn_cancel');
                var parent = btnOk.getParent();
                if (type == 'alert0') {
                    btnOk.setVisible(false);
                    btnCancel.setVisible(false);
                }
                else if (type == 'alert1') {
                    btnOk.setVisible(true);
                    btnCancel.setVisible(false);
                    btnOk.setPositionX(parent.getContentSize().width / 2);
                }
                else if (type == 'alert2') {
                    btnOk.setVisible(true);
                    btnCancel.setVisible(true);
                }
            }

            TouchUtils.setOnclickListener($('root.fake_root'), function () {
                if (!canCancel)
                    return;
                if (onCancel)
                    onCancel();
                that.removeFromParent(true);
            });
            TouchUtils.setOnclickListener($('root.panel.btn_ok'), function (node) {
                if (onOk)
                    onOk();
                that.removeFromParent(true);
            });
            TouchUtils.setOnclickListener($('root.panel.btn_cancel'), function (node) {
                if (onCancel)
                    onCancel();
                that.removeFromParent(true);
            });
            TouchUtils.setOnclickListener($('root.panel.btn_close'), function (node) {
                that.removeFromParent(true);
            });

            return true;
        },
        setContent: function (str) {
            $('root.panel.lb_content').setString(str);
        }
    });

    exports.TishiLayer = TishiLayer;
})(window);
